// db/index.js
const mongoose = require('./db')

// 这是一个 模型 一个表

// ----------end
class Mongodb {
 
  constructor() {
      this.Schema = mongoose.Schema;
      // 
      this.Sch_getnewslist = new this.Schema({
      id: Number,
      title: String,
      add_time: String,
      zhaiyao: String,
      click: Number,
      img_url: String
    });

     this.Mol_getnewslist = mongoose.model('ceshi', this.Sch_getnewslist);
    
    // 第一步 定义模型，第二步 去定义创建表格
    this.Sch_getnew = new this.Schema({
      id: Number,
      title: String,
      click:Number,
      add_time: String,
      content: String,      
      
    });
     this.Mol_getnew = mongoose.model('getnew', this.Sch_getnew);
     //***
     this.Sch_getimages = new this.Schema({
      id: Number,
      title: String,
      img_url:String,
      add_time: String,
      zhaiyao: String,      
      
    });
     this.Mol_getimages = mongoose.model('getimages', this.Sch_getimages);
     //*** getimgcategory
     this.Sch_getimgcategory = new this.Schema({
      id: Number,
      title: String,
         
      
    });
     this.Mol_getimgcategory = mongoose.model('getimgcategory', this.Sch_getimgcategory);
     
     //***
     this.Mol_getthumimages = mongoose.model('getimages', this.Sch_getimages);
     //*** getimgcategory
     this.Sch_getthumimages = new this.Schema({
      src:String        
      
    });
     this.Mol_getthumimages = mongoose.model('getthumimages', this.Sch_getthumimages);
  }

  // 查询
  query(mongoose_mod) {
    return new Promise((resolve, reject) => {
      mongoose_mod.find({}, (err, res) => {
        if (err) {
          reject(err)
        }
        resolve(res)
      })
    })
  }
  // 保存
 
  createTable_getnewlist(id, title, add_time, zhaiyao, click, img_url) {
    const index = new this.Mol_getnewslist({ id: id, title: title, add_time: add_time, zhaiyao: zhaiyao, click: click, img_url: img_url });
    index.save();
  
  }
  
  createTable_getnew(id,title, click, add_time, content) {
    const index = new this.Mol_getnew({ id: id, title: title, add_time: add_time, click:click ,content:content});
    index.save();
  }
  createTable_getimages(id, title, img_url, zhaiyao) {
    const index = new this.Mol_getimages({ id: id, title: title, img_url: img_url, zhaiyao: zhaiyao   });
    index.save();
  
  }
  createTable_getimgcategory(id, title) {
    const index = new this.Mol_getimgcategory({ id: id, title: title });
    index.save();
  
  }
}
module.exports = new Mongodb()

